<template>
  <div class="wrap">
    <h3>用户登录</h3>
    <el-form :model="formInline" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="formInline.user" placeholder="账号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="formInline.pass"
          placeholder="密码"
          show-password
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          placeholder="图形验证码"
          v-model="formInline.v_code"
          style="width: 40%"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-checkbox>记住密码</el-checkbox>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit" style="width: 100%"
          >登录</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      formInline: {
        user: "",
        pass: "",
        v_code: "",
      },
    };
  },
  mounted() {},
  methods: {
    onSubmit() {
      if (this.formInline.user.length == 0) {
        this.$message.error("账户不能为空");
      } else if (this.formInline.pass.length == 0) {
        this.$message.error("密码不能为空");
      } else if (this.formInline.v_code.length == 0) {
        this.$message.error("验证码不能为空");
      }
      this.$axios
        .post("http://ceshi5.dishait.cn/admin/login", {
          username: this.formInline.user,
          password: this.formInline.pass,
        })
        .then((res) => {
          if (res.data.msg == "ok") {
            //   console.log(res.data.data.token);
            localStorage.setItem("token",res.data.data.token);
            this.$router.push({ path: "/Home" });
            this.$message.success("登录成功");

          }
        })
        .catch(() => {
          this.$message.error("登录失败，账户或密码错误");
        });
    },
  },
};
</script>
<style lang="scss" scoped>
.wrap {
  width: 360px;
  margin: 80px auto;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 20px 2px rgba(0, 0, 0, 0.1);
  padding: 20px 30px;
  border-radius: 10px;
  h3 {
    margin: 10px 0 24px 0;
    text-align: center;
  }
}
</style>